public class SolutionInterview10_9 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int x=matrix.length-1,y=0;
        while (x>=0 && y<matrix[0].length){
            if (matrix[x][y]==target){
                return true;
            }
            if (matrix[x][y]>target){
                x--;
            }else {
                y++;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview10_9().searchMatrix(new int[][]{{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}},5));
    }
}
